﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _1.OrderService.Query
{
    public partial class QueryByProductForm : Form
    {
        QueryForm _queryForm;
        OrderService _orderService;
        public QueryByProductForm(QueryForm queryForm,OrderService orderService)
        {
            InitializeComponent();
            _queryForm = queryForm;
            _orderService = orderService;
            Label head = new Label();
            head.Size = new Size(300, 30);
            head.Text = " 订单单号     商品名称     客户名称      订单金额 ";
            panel1.Controls.Add(head);
        }

        private void QueryByProductForm_Load(object sender, EventArgs e)
        {

        }

        private void button_quit_Click(object sender, EventArgs e)
        {
            _queryForm.Show();
            this.Close();
        }

        private void button_query_Click(object sender, EventArgs e)
        {
            panel1.Controls.Clear();
            Label head = new Label();
            head.Size = new Size(300, 30);
            head.Text = " 订单单号     商品名称     客户名称      订单金额 ";
            panel1.Controls.Add(head);
            string productName = textBox1.Text;
            var queryAns = from order in _orderService.orders where order.orderDetail.productName == productName orderby order.orderDetail.orderAmount select order;
            int i = 0;
            foreach (Order order in queryAns)
            {
                Label label = new Label();
                label.Size = new Size(300, 30);
                label.Text = order.ToString();
                panel1.Controls.Add(label);
                label.Location = new Point(0, (i + 1) * 30);
                i += 1;
            }
        }
    }
}
